import Vue from 'vue';


import Axios from 'axios';
import ElementUI from 'element-ui';

import '@/assets/reset.css';
import '@/assets/index.css';
import '@/static/css/comment.css';

// import "@/assets/md/markdown.css";
// markdown相关
// import mavonEditor from 'mavon-editor'
// import 'mavon-editor/dist/css/index.css'

import marked from 'marked';
import hljs from 'highlight.js';
import 'highlight.js/styles/default.css';

import Md5 from 'js-md5';
import store from './store';
import router from './router';
import App from './App.vue';

// Vue.use(mavonEditor);
Vue.use(ElementUI);

Vue.prototype.$http = Axios;

Vue.prototype.$marked = marked;

Vue.directive('highlight', (el) => {
  const blocks = el.querySelectorAll('pre code');
  blocks.forEach((block) => {
    hljs.highlightBlock(block);
  });
});


Vue.config.productionTip = false;


const BASE_API = 'http://47.91.165.159:8084';
// let BASE_API = "http://127.0.0.1:8084";

const SITE_API = `${BASE_API}/site`;
const ARTICLE_API = `${BASE_API}/article`;
const CLASSIFICATION_API = `${BASE_API}/classification`;
const COMMENT_API = `${BASE_API}/comment`;
const PIGEONHOLE_API = `${BASE_API}/pigeonhole`;
const SEARCH_API = `${BASE_API}/search`;

Vue.prototype.SITE_API = SITE_API;
Vue.prototype.ARTICLE_API = ARTICLE_API;
Vue.prototype.CLASSIFICATION_API = CLASSIFICATION_API;
Vue.prototype.COMMENT_API = COMMENT_API;
Vue.prototype.PIGEONHOLE_API = PIGEONHOLE_API;
Vue.prototype.SEARCH_API = SEARCH_API;

// 封装加密的方法
Vue.prototype.doSign = function (json) {
  const j = JSON.stringify(json).replace(/\"/g, '');
  return Md5.hex(`${j}123`);
};


/**
 * 初始化系统相关
 */
Vue.prototype.initializeSystem = function (e) {
  let nightFlag = localStorage.getItem('nightFlag');
  if (nightFlag === null || nightFlag === 'NaN') {
    nightFlag = 0;
  }
  console.log(`.. .. .. ${nightFlag}`);
  e.$store.state.nightFlag = nightFlag;
};


new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App),
});


// new Vue({
//   render: h => h(App),
// }).$mount('#app');
